<?php
/**
 * Created by PhpStorm.
 * User: zyark
 * Date: 2018/4/2
 * Time: 11:22
 */

namespace app\index\controller;


use app\common\controller\Frontend;
use app\common\utils\Constant;
use app\common\utils\PayNotifyCallBack;
use app\index\logic\AnswerLogic;
use app\index\logic\RedEnvelopeLogic;
use app\index\logic\RepairLogic;
use think\cache\driver\Redis;
use think\Loader;
use think\Log;

class Repair extends Frontend{

    /**
     * ajax提交报事报修
     * @return \think\response\Json
     */
    public function ajax_add_repair(){
        $result = $this->check();
        if(!$result['success']){
            return $this->returnJson($result['msg'],$result['code']);
        }
        $params = $this->request->post();
        if(empty($params['remark'])){
            return $this->returnJson('请输入描述', Constant::CODE_ERROR);
        }
        if(empty($params['house_property_id'])){
            return $this->returnJson('请选择房产', Constant::CODE_ERROR);
        }
        $re = RepairLogic::getInstance()->addRepair($result['user_id'], $params['house_property_id'], $params['remark']);
        return $this->returnJson($re['msg'], $re['code'], []);
    }

    /**
     * ajax获取报修记录
     * @return \think\response\Json
     */
    public function ajax_repair_list(){
        $result = $this->check();
        if(!$result['success']){
            return $this->returnJson($result['msg'],$result['code']);
        }
        $house_property_id = $this->request->post('house_property_id');
        $data['page_size'] = $this->request->post('page_size');
        $data['page_num'] = $this->request->post('page_number');
        $data['user_id'] = $result['user_id'];
        $data['house_property_id'] = $house_property_id;
        $logic = new RepairLogic();
        $result = $logic->getRepairList($data);
        return $this->returnJson('',Constant::CODE_SUCCESS,$result);
    }


//    public function test(){
//        $log['house_property_id'] = 1;
//        $log['user_id'] = 4;
//        $log['remark'] = '房子漏水快来修';
//        $log['create_time'] = time();
//        $log['village_id'] = 1;
//        $log['status'] = 0;
//        model('Repair')->insert($log);
//    }

}